package com.ram.app.controller;


import com.ram.app.service.RamUserService;
import com.ram.common.entity.RamUser;
import com.ram.common.entity.wrapper.UserWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author fudongjing
 * @since 2018-07-07
 */
@RestController
@RequestMapping("/user")
@Api(tags = "用户信息表", description = "用户登录信息")
public class UserController {

    @Autowired
    private RamUserService ramUserService;

    @ApiOperation("用户登录接口")
    @GetMapping("/findUserByUsername")
    public UserWrapper findUserByUsername(@RequestParam ("userName")String username) throws Exception {
        UserWrapper wrapper = ramUserService.getUserByName(username);
        return wrapper;
    }

    @ApiOperation("用户注册")
    @PostMapping("/registerUser")
    public Boolean registerUser(@RequestBody RamUser user) throws Exception {
        return this.ramUserService.registerUser(user);
    }
    @ApiOperation("电话号码唯一验证")
    @GetMapping("/valitedPhone")
    public Boolean valitedPhone(@RequestParam("phoneNum")String phoneNum) throws Exception {
        //电话号码为空验证
        if(StringUtils.isEmpty(phoneNum)){
            return false;
        }
        return this.ramUserService.valitedPhone(phoneNum);
    }


}

